package jjn.carl.stack_queue;

import java.util.Objects;

/**
 * @author Jiang Jining
 * @since 2023-07-09 14:54
 */
public class LeetCode1047 {
    public String removeDuplicates(String s) {
        StringBuilder stringBuilder = new StringBuilder();
        for (char c : s.toCharArray()) {
            if (stringBuilder.isEmpty() || !Objects.equals(stringBuilder.charAt(stringBuilder.length() - 1), c)) {
                stringBuilder.append(c);
            } else {
                stringBuilder.deleteCharAt(stringBuilder.length() - 1);
            }
        }
        return stringBuilder.toString();
    }
    
    public static void main(String[] args) {
        String removedDuplicates = new LeetCode1047().removeDuplicates("abbaca");
        System.out.println("removedDuplicates = " + removedDuplicates);
    }
}
